package com.seelyn.rhea.mvc.render;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author linfeng
 * @since 2016/1/20
 */
public abstract class AbstractView<T extends Serializable> implements View<T> {

    public static final String JS_CONTENT_TYPE = "application/javascript;charset=UTF-8";
    public static final String JSON_CONTENT_TYPE = "application/json;charset=UTF-8";
    public static final String HTML_CONTENT_TYPE = "text/html;charset=UTF-8";
    public static final String XML_CONTENT_TYPE = "text/xml;charset=UTF-8";
    public static final String PLAIN_CONTENT_TYPE = "text/plain;charset=UTF-8";
    private static final long serialVersionUID = 3257649648073294649L;

    private final Map<String, Object> flashMap = new HashMap<String, Object>();
    private final String contentType;

    protected AbstractView(String contentType) {
        this.contentType = contentType;
    }

    @Override
    public String getContentType() {
        return contentType;
    }

    @Override
    public void setAttribute(String key, Object value) {
        flashMap.put(key, value);
    }

    @Override
    public Map<String, Object> getAttributes() {
        return flashMap;
    }

    public Map<String, Object> getFlashMap() {
        return flashMap;
    }
}
